Dart BigInt operator +
Syntax & Examples


BigInt.operator + operator

The `+` operator adds this BigInt to another BigInt.


Syntax of BigInt.operator +

The syntax of BigInt.operator + operator is:

operator +(BigInt other) → BigInt

This operator + operator of BigInt addition operator.

Parameters

ParameterOptional/RequiredDescription
otherrequiredthe BigInt to be added


✐ Examples

1 Add two positive BigInts

In this example,

  1. We define two positive BigInts, num1 with a value of 10 and num2 with a value of 20.
  2. We use the `+` operator to add them.
  3. We print the sum to standard output.

Dart Program

void main() {
  BigInt num1 = BigInt.from(10);
  BigInt num2 = BigInt.from(20);
  BigInt sum = num1 + num2;
  print('Sum: $sum');
}

Output

Sum: 30

2 Add a negative and a positive BigInt

In this example,

  1. We define a negative BigInt num1 with a value of -10 and a positive BigInt num2 with a value of 20.
  2. We use the `+` operator to add them.
  3. We print the sum to standard output.

Dart Program

void main() {
  BigInt num1 = BigInt.from(-10);
  BigInt num2 = BigInt.from(20);
  BigInt sum = num1 + num2;
  print('Sum: $sum');
}

Output

Sum: 10

3 Add a positive and a negative BigInt

In this example,

  1. We define a positive BigInt num1 with a value of 10 and a negative BigInt num2 with a value of -20.
  2. We use the `+` operator to add them.
  3. We print the sum to standard output.

Dart Program

void main() {
  BigInt num1 = BigInt.from(10);
  BigInt num2 = BigInt.from(-20);
  BigInt sum = num1 + num2;
  print('Sum: $sum');
}

Output

Sum: -10

Summary

In this Dart tutorial, we learned about operator + operator of BigInt: the syntax and few working examples with output and detailed explanation for each example.